﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Threading.Tasks;
using Entity;

namespace IService
{
    public interface IInventoryService
    {
        Task<InventoryListEntity> CreateInventoryListAsync(InventoryListEntity entity, List<InventoryDetailsEntity> details);
        Task<InventoryListEntity> GetInventoryListByOrderNoAsync(string orderNo);
        Task UpdateInventoryListStatusAsync(int listId, int status, string reviewer = null);
        Task CancelInventoryListAsync(int listId);
        Task BatchCancelInventoryListAsync(List<int> listIds);
        Task<PaginationResult<InventoryListEntity>> GetInventoryListAsync(InventoryListQueryParams queryParams);
        Task UpdateInventoryListAsync(InventoryListEntity entity, List<InventoryDetailsEntity> details);
        Task<System.IO.MemoryStream> ExportInventoryListAsync(InventoryListQueryParams queryParams);
        Task AddInventoryDetailsAsync(int listId, List<InventoryDetailsEntity> details);
        Task UpdateInventoryDetailAsync(InventoryDetailsEntity detail);
        Task<List<InventoryDetailsEntity>> GetInventoryDetailsByListIdAsync(int listId);
        Task AdjustInventoryAsync(int listId);
        Task<InventoryListEntity> GetInventoryListByIdAsync(int id);
        Task LockWarehouseAsync(string warehouseName);
        Task<List<WarehouseEntity>> GetAllWarehousesAsync();
        Task DeleteInventoryDetailAsync(int detailId);
        Task DeleteInventoryListAsync(int listId);
        Task BatchDeleteInventoryListAsync(List<int> listIds);
        Task<bool> CheckWarehouseLockAsync(string warehouseName);
        Task<List<StorageLocationEntity>> GetAllStorageLocationsAsync();
        Task<List<StorageLocationEntity>> GetStorageLocationsByWarehouseAsync(string warehouseName);
        /// <summary>
        /// 为调拨单调整库存
        /// </summary>
        /// <param name="outWarehouseId">调出仓库ID</param>
        /// <param name="inWarehouseId">调入仓库ID</param>
        /// <param name="details">调拨单明细</param>
        /// <returns>是否调整成功</returns>
        Task<bool> AdjustInventoryForTransfer(int outWarehouseId, int inWarehouseId, List<TransferOrderDetailDTO> details);
        Task<bool> RollbackInventoryForTransfer(
        int outWarehouseId,
        int inWarehouseId,
        List<TransferOrderDetailDTO> details);
        // 新增带事务的重载方法（核心）
        /// <summary>
        /// 带事务的调拨库存调整（接口定义）
        /// </summary>
        Task<bool> AdjustInventoryForTransfer(
            int outWarehouseId,
            int inWarehouseId,
            List<TransferOrderDetailDTO> details,
            DbTransaction transaction);
        Task<bool> RollbackInventoryForTransfer(int outWarehouseId, int inWarehouseId, List<TransferOrderDetailDTO> details, DbTransaction transaction);
        Task ApproveInventoryAsync(int inventoryId, string reviewer);
        Task<int> GetCurrentStockByProductCodeAsync(string productCode);
        Task<int> GetCurrentStockByProductCodeAsync(string productCode, string warehouseName);
        Task<int> GetCurrentStockByProductAndLocationAsync(string productCode, string warehouseName, string locationName);

    }
}